package com.ems.controller.Invigilate.room;

import com.ems.pojo.Invigilate.room.ExaminationPaper;
import com.ems.pojo.data.RequestData;
import com.ems.pojo.data.ResultData;
import com.ems.pojo.data.RetunResult;
import com.ems.pojo.data.ReturnPageResult;
import com.ems.pojo.user.User;
import com.ems.service.Invigilate.room.ExaminationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Auther: 伟伟
 * @Date: 2020/2/18
 * @Description: 描述
 * @Version: 1.0
 */
@Controller
@CrossOrigin //允许所有ip跨域
@RequestMapping("/examinationPaper")
public class ExaminationPaperController {
    @Autowired
    @Qualifier("examinationService")
    private ExaminationService examinationService;

    @ResponseBody
    @RequestMapping("/addExaminationPaper")
    public ResultData addExaminationPaper(@RequestBody ExaminationPaper examinationPaper, HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("user");
        examinationPaper.setId(user.getId());
        examinationService.addExaminationPaper(examinationPaper);
        return RetunResult.AssemblyData();
    }

    /**
     * 根据条件获取生成的试题
     * @param requestData
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/getExaminationPaper")
    public ResultData getExaminationPaper(@RequestBody RequestData requestData, HttpServletRequest request){
        ReturnPageResult.setPageHelperInfo(requestData);
        User user = (User) request.getSession().getAttribute("user");
        List<ExaminationPaper> list = examinationService.getExaminationPaper(requestData.getMap(),user);
        return ReturnPageResult.AssemblyData(list);
    }

    /**
     * 根据id获取试题的详细信息
     * @param examinationPaper
     * @return
     */
    @ResponseBody
    @RequestMapping("/getExaminationPaperById")
    public ResultData getExaminationPaperById(@RequestBody ExaminationPaper examinationPaper){
        ExaminationPaper examinationPaper1 = examinationService.getExaminationPaperById(examinationPaper);
        return RetunResult.AssemblyData(examinationPaper1);
    }

    /**
     * 根据id获取试题的详细信息（不包含答案）
     * @param examinationPaper
     * @return
     */
    @RequestMapping("/getNoAnswerExaminationPaperById")
    @ResponseBody
    public ResultData getNoAnswerExaminationPaperById(@RequestBody ExaminationPaper examinationPaper){
        ExaminationPaper examinationPaper1 = examinationService.getNoAnswerExaminationPaperById(examinationPaper);
        return RetunResult.AssemblyData(examinationPaper1);
    }

    /**
     * 改卷
     * @param examinationPaper
     * @return
     */
    @RequestMapping("/rewinding")
    @ResponseBody
    public ResultData rewinding(@RequestBody ExaminationPaper examinationPaper,HttpServletRequest request){
        User user = (User) request.getSession().getAttribute("user");
        examinationPaper.setId(user.getId());
        examinationService.rewinding(examinationPaper);
        return RetunResult.AssemblyData();
    }

    /**
     * 根据id修改试题信息
     * @param examinationPaper
     * @return
     */
    @ResponseBody
    @RequestMapping("/updateExaminationById")
    public ResultData updateExaminationById(@RequestBody ExaminationPaper examinationPaper){
        examinationService.updateExaminationById(examinationPaper);
        return RetunResult.AssemblyData();
    }

    /**
     * 根据id批量删除试题
     * @param examinationPaperList
     * @return
     */
    @ResponseBody
    @RequestMapping("/deleteExaminationById")
    public ResultData deleteExaminationById(@RequestBody List<ExaminationPaper> examinationPaperList){
        examinationService.deleteExaminationById(examinationPaperList);
        return RetunResult.AssemblyData();
    }


}
